//
//  CYWelcomeViewController.swift
//  WeiBo
//
//  Created by Mr_J on 16/3/8.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit
import SDWebImage

class CYWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
    }
    
    private func setupUI() {
        view.backgroundColor = UIColor.whiteColor()
        
        view.addSubview(headImageView)
        view.addSubview(welcomeLabel)
        
        headImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.view)
            make.top.equalTo(200)
            make.size.equalTo(CGSizeMake(90, 90))
        }
        welcomeLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(headImageView)
            make.top.equalTo(headImageView.snp_bottom).offset(20)
        }
        
        
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        headImageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(100)
        }
        
        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity:0, options: [], animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                
                UIView.animateWithDuration(1, animations: { () -> Void in
                    self.welcomeLabel.alpha = 1
                    },completion:{ (_) -> Void in
                        print("跳转页面")
                        
//                        let delegate = UIApplication.sharedApplication().delegate! as! AppDelegate
//                        let window = delegate.window
//                        
//                        window?.rootViewController = CYMainViewCotroller()
                        NSNotificationCenter.defaultCenter().postNotificationName("Cyr", object: self)
                    })
                
        }
        
    }
    
    
    private lazy var headImageView: UIImageView = {
       let imageVeiw = UIImageView(image: UIImage(named: "avatar_default_big"))
        imageVeiw.layer.cornerRadius = 45
        imageVeiw.layer.masksToBounds = true
        let headImageUrlStr = CYUserAccountViewModel.sharedAccountViewModel.account?.avatar_large
        print(CYUserAccountViewModel.sharedAccountViewModel.account)
        imageVeiw.sd_setImageWithURL(NSURL(string: headImageUrlStr!), placeholderImage: UIImage(named: "avatar_default_big"))
        return imageVeiw
    }()
    
    private lazy var welcomeLabel: UILabel = {
       let label = UILabel(textColor: UIColor.darkGrayColor(), fontSize:16)
        label.text = "欢迎回来"
        label.sizeToFit()
        label.alpha = 0
        return label
    }()
    
    
}
